package run;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.FileWriter;

//Converts a cell to a dot file
public class DotConverter {

	BufferedWriter writer;
	public DotConverter(String filename)
	{
		try
		{
			writer = new BufferedWriter(new FileWriter(filename));
		}
		catch(IOException e)
		{
			System.out.println("ERROR!!!! CAN'T WRITE DOT GRAPH!!!!");
		}
	}
	
	public void startDotFile()
	{
		try
		{
			writer.write("digraph G {\n");
		}
		catch(IOException e)
		{
			System.out.println("ERROR WHILE WRITING DOT GRAPH");
		}
	}
	
	public void endDotFile()
	{
		try
		{
			writer.write("}\n");
			writer.close();
		}
		catch(IOException e)
		{
			System.out.println("ERROR WHILE WRITING DOT GRAPH");
		}
	}
	
	public void convert(Cell c)
	{
		try
		{
			String prefix = "x";
			writer.write(c.toDot(prefix));
		}
		catch(IOException e)
		{
			System.out.println("ERROR WHILE WRITING DOT GRAPH");
		}	
	}
}
